local COLORS = { Color3.fromRGB(31, 39, 68), Color3.fromRGB(255, 250, 240) } local boardPos = owner.Character.HumanoidRootPart.CFrame * CFrame.new(0, -3, -10) local board = Instance.new("Part") board.BrickColor = BrickColor.new("Bright green") board.Material = Enum.Material.Concrete board.Size = Vector3.new(8, 0.25, 8) board.CFrame = boardPos * CFrame.new(0, 0.125, 0) board.Anchored = true board.Parent = script do local texture = Instance.new("Texture") texture.Texture = "rbxassetid://41116694" texture.StudsPerTileU = 1 texture.StudsPerTileV = 1 texture.Face = Enum.NormalId.Top texture.Parent = board end local canPlay = false local grid = table.create(8) local parts = table.create(8) local valid = {} local players = {} local turn = 1 local function draw() for x = 1, 8 do for y = 1, 8 do local part = parts[x][y] if grid[x][y] == 0 then part.Transparency = 1 elseif grid[x][y] >= 0 then part.Transparency = 0 part.Color = COLORS[grid[x][y]] or Color3.new(1, 0, 1) end end end for k, v in pairs(valid) do if v then local xs, ys = string.match(k, "(%d),(%d)") local x, y = tonumber(xs), tonumber(ys) parts[x][y].Transparency = 0.5 parts[x][y].Color = COLORS[turn] or Color3.new(1, 0, 1) end end end local function place(x, y, c, simulate) if grid[x][y] ~= 0 then return false end local ret = false for dx = -1, 1 do for dy = -1, 1 do if dx == 0 and dy == 0 then continue end local px, py = x + dx, y + dy local this, other = false, false while grid[px] and grid[px][py] do if grid[px][py] == c then this = true break elseif grid[px][py] == 0 then break elseif grid[px][py] ~= c then other = true end if this and other then break end px += dx py += dy end if this and other then ret = true if not simulate then grid[x][y] = c local px, py = x + dx, y + dy while grid[px] and grid[px][py] and grid[px][py] ~= c and grid[px][py] ~= 0 do grid[px][py] = c px += dx py += dy end end end end end return ret end local function checkValid() valid = {} local canMove = false for x = 1, 8 do for y = 1, 8 do if place(x, y, turn, true) then canMove = true valid[x .. "," .. y] = true end end end return canMove end local function reset() for x = 1, 8 do for y = 1, 8 do if x >= 4 and x <= 5 and y >= 4 and y <= 5 then grid[x][y] = 2 - (x+y)%2 else grid[x][y] = 0 end end end turn = 1 checkValid() draw() canPlay = true end local function endGame() canPlay = false local black, white = 0, 0 for x = 1, 8 do for y = 1, 8 do if grid[x][y] == 1 then black += 1 elseif grid[x][y] == 2 then white += 1 end end end if black > white then print("Black wins!") elseif white > black then print("White wins!") else print("It's a draw!") end print("Black: " .. black .. " - White : " .. white) task.wait(5) reset() end local function click(player, x, y) if not canPlay then return end if valid[x .. "," .. y] then place(x, y, turn, false) local skip = 0 repeat turn = (turn == 1 and 2 or 1) skip += 1 until skip >= 3 or checkValid() draw() if skip >= 3 then endGame() end end end for x = 1, 8 do grid[x] = table.create(8, 0) parts[x] = table.create(8) for y = 1, 8 do local part = Instance.new("Part") part.Anchored = true part.CFrame = boardPos * CFrame.new(-4.5 + x, 0.375, -4.5 + y) * CFrame.Angles(0, 0, math.pi/2) part.Shape = Enum.PartType.Cylinder part.Size = Vector3.new(0.25, 1, 1) part.Material = Enum.Material.SmoothPlastic part.CanCollide = false part.Parent = script local clickDetector = Instance.new("ClickDetector") clickDetector.MouseClick:Connect(function(player) click(player, x, y) end) clickDetector.Parent = part parts[x][y] = part end end reset()